<?php
/**
 * Shortcode Functions
 *
 */

//Long posts should require a higher limit, see http://core.trac.wordpress.org/ticket/8553
@ini_set('pcre.backtrack_limit', 500000);

/**
 * Disable Automatic Formatting on Posts
 *
 * @param string $content
 * @return string
 */
function webtreats_formatter($content) {

	$new_content = '';
	
	/* Matches the contents and the open and closing tags */
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	
	/* Matches just the contents */
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	
	/* Divide content into pieces */
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	/* Loop over pieces */
	foreach ($pieces as $piece) {
	
		/* Look for presence of the shortcode */
		if (preg_match($pattern_contents, $piece, $matches)) {
		
			/* Append to content (no formatting) */
			$new_content .= $matches[1];
		
		} else {
		
			/* Format and append to content */
			$new_content .= wptexturize(wpautop($piece));
		
		}
	}

	return $new_content;
}


/* Remove the 2 main auto-formatters */
remove_filter('the_content',	'wpautop');
remove_filter('the_content',	'wptexturize');

/* Before displaying for viewing, apply this function */
add_filter('the_content', 'webtreats_formatter', 99);
add_filter('widget_text', 'webtreats_formatter', 99);

/**
 * Portfolio Gallery Shortcode.
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display portfolio gallery.
 */
function custom_portfolio_gallery_sc($atts) {
	global $post, $wpdb;
	
	extract(shortcode_atts(array(
		'cat' => '',
		'column' => '4',
		'link' => 'image',
		'max' => '12',
		
	), $atts));
	
	//gallery ID based on category & column layout
	$set_id = $cat.$column;
	

	//start custom WP_Query for portfolio posts
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	
	$portfolio_query = new WP_Query();
	$portfolio_query->query("cat=$cat&posts_per_page=$max&paged=$paged");
		
	$out .= '<div class="gallery_set">';
	
	//start the loop
	$counter = 0;
	
	if($portfolio_query->have_posts()) : while($portfolio_query->have_posts()) : $portfolio_query->the_post();
	
	//get portfolio post meta
	$post_title = get_the_title($post->ID);
	$permalink = get_permalink($post->ID);
	
	$portfolio_date = get_post_meta($post->ID, 'portfolio_date',true);
	$portfolio_link = get_post_meta($post->ID, 'portfolio_link',true);
	$portfolio_gallery = get_post_meta($post->ID, 'portfolio_gallery_img',true);
	$portfolio_full = get_post_meta($post->ID, 'portfolio_full_img',true);
	$portfolio_video = get_post_meta($post->ID, 'portfolio_video_link',true);
	$portfolio_teaser = get_post_meta($post->ID, 'portfolio_teaser_text',true);
	$read_more_disable = get_post_meta($post->ID, 'portfolio_read_disable',true);
	
	//define coloumn class
	$column = ($column <= 0 || $column > 4) ? 4 : $column;
	$class = ($column == 4) ? ' one_fourth' : 'one_fourth';
	$class = ($column == 3) ? ' one_third' : $class;
	$class = ($column == 2) ? ' one_half' : $class;
	$class = ($column == 1) ? ' two_third' : $class;
	
	//define image height & width
	if($column == 4){ $img_height = '110'; $img_width = '176'; }
	if($column == 3){ $img_height = '160'; $img_width = '255'; }
	if($column == 2){ $img_height = '260'; $img_width = '412'; }
	if($column == 1){ $img_height = '355'; $img_width = '570'; }

	//define gallery image
	$image_url = ($portfolio_gallery) ? $portfolio_gallery : $portfolio_full;
	$gallery_image_url = webtreats_image_resize($img_height,$img_width,$image_url);
	
	//if portfolio fullsize defined output gallery image
	if($portfolio_full){ 
		
		$counter++;
		$last = ($counter == $column && $column != 1) ? ' last' : '';
				
		$portfolio_title = (!$read_more_disable) ? '<a href="' .$permalink. '">' .$post_title. '</a>' : $post_title;
		$portfolio_links = ($portfolio_video) ? $portfolio_video : $portfolio_full;
		$hover_class = ($portfolio_video) ? ' portfolio_item_media' : ' portfolio_item';
		
		$out .= '<div class="img_loader' .$hover_class. ' bg_hover' .$class.$last. '">';
		
		$portfolio_img_link = ($link == 'post' && !$portfolio_video) ? $portfolio_img_link = 'href="' .$permalink : $portfolio_img_link = 'rel="lightbox[' .$set_id. ']" href="' .$portfolio_links;
			
		$out .= '<a class="load_img" ' .$portfolio_img_link. '"><span class="rm_img noscript"><img class="framed portfolio_hover" src="' .$gallery_image_url. '" height="' .$img_height. '" width="' .$img_width. '" alt="" /></span></a>';
		
		if($column != 1){
			$out .= '<h3>' .$portfolio_title. '</h3>';
			if($portfolio_date){ $out .= '<p class="date">' .$portfolio_date. '</p>'; }
			if($portfolio_teaser){ $out .= '<p>' .do_shortcode($portfolio_teaser). '</p>'; }
			if(!$read_more_disable){ $out .= '[raw]<a class="fancy_link" href="' .$permalink. '"><span>Read More</span></a>[/raw]'; }
			if($portfolio_link){ $out .= '[raw]&nbsp;<a class="fancy_link target_blank" href="' .$portfolio_link. '"><span>Visit Site</span></a>[/raw]'; }
		}

		$out .= '</div>';
		
		if($column == 1){
			$out .= '<div class="one_third last">';
			$out .= '<h2>'. $portfolio_title. '</h2>';
			if($portfolio_date){ $out .= '<p class="date">' .$portfolio_date. '</p>'; }
			if($portfolio_teaser){ $out .= '<p>' .do_shortcode($portfolio_teaser). '</p>'; }
			if(!$read_more_disable){ $out .= '[raw]<a class="button_link" href="' .$permalink. '"><span>Read More</span></a>[/raw]'; }
			if($portfolio_link){ $out .= '[raw]&nbsp;<a class="button_link target_blank" href="' .$portfolio_link. '"><span>Visit Site</span></a>[/raw]'; }
			$out .= '</div>';
		}
		
	}
	
	$clearboth = ($counter == $column) ? '<div class="clearboth"></div>' : '';
	$out .= $clearboth;
	
	if($counter == $column){$counter = 0;}
	
	endwhile; endif;
	
	$out .= webtreats_portfolio_pagenavi($before = '', $after = '', $portfolio_query, $paged);
	
	wp_reset_query(); 
	
	$out .='</div>';
	
	return $out;
	
}
add_shortcode('portfolio', 'custom_portfolio_gallery_sc');

/**
 * Recent Tweets from Twitter Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display recent Tweets
 */
function webtreats_twitter_widget_sc($atts) {
	global $shortname;
	$get_options = get_option($shortname.'_general_settings');
	
	$usernames = $get_options['twitter_id']; $type = 'widget';
	
	extract(shortcode_atts(array(
		'count' => '5',
		'username' => $usernames,
		
	), $atts));
	

	$out .= '<div class="webtreats_twitter_widget">';
   	$out .= '<ul>';
	$out .= parse_cache_twitter_feed($username, $count, $type);
	$out .= '</ul>';
	$out .= '</div>';
	
	return $out;
}
add_shortcode('twitter', 'webtreats_twitter_widget_sc');

/**
 * Photos from Flickr Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display photos from Flickr
 */
function webtreats_flickr_widget_sc($atts) {
    extract(shortcode_atts(array(
        	'id'      => '44071822@N08',
		'count'      => '9',
		'display'      => 'latest',
		'size'      => 'square',
    ), $atts));

	if($size == 'square'){ $size = 's'; }
	if($size == 'thumbnail'){ $size = 't'; }
	if($size == 'medium'){ $size = 'm'; }
	
    $out .= '<div class="webtreats_flickr_widget">';
	$out .= '[raw]<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=' .$count. '&amp;display=' .$display. '&amp;size=' .$size. '&amp;layout=x&amp;source=user&amp;user=' .$id. '"></script>[/raw]';	
	$out .= '<div class="clearboth"></div></div>';
    
    return $out;
}
add_shortcode('flickr', 'webtreats_flickr_widget_sc');

/**
 * Recent Blog Posts Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display recent blog posts
 */
function webtreats_recent_post_widget_sc($atts) {
	global $wpdb, $shortname;
	
	extract(shortcode_atts(array(
        	'count'      => '3',
		'thumbnail'      => 'true',
    ), $atts));


	$get_options = get_option($shortname.'_general_settings');
	$blog_excludecats = $get_options['blog_excludecats'];
	$exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
	$posts = get_posts("cat=$exclude_blog_cats&numberposts=$count&offset=0");

	if($posts){
		
		$out .= '<div id="popular-widget" class="scg_widget blog webtreats_popular_widget">';
		$out .= '<ul class="thumbnail_list">';
		
		foreach($posts as $post){

			$post_title = stripslashes($post->post_title);
			$post_date = $post->post_date;
			$post_date = mysql2date('m-j-Y', $post_date, false);
			$get_year = get_the_time('Y', $post->ID); $get_month = get_the_time('m', $post->ID);
			$permalink = get_permalink($post->ID);
			$meta_image = get_post_meta($post->ID, "post_image", true);
			
			if(!$meta_image){
				$meta_image = get_template_directory_uri() .'/styles/_shared/default_post_thumb_small.png';
			}else{
				
				if(preg_match_all('!.+\.(?:jpe?g|png|gif)!Ui',$meta_image,$matches)){
					$meta_image = webtreats_image_resize($img_height=60, $img_width=60, $meta_image);	
				}
				
				if( ( preg_match_all('#http://(www.vimeo|vimeo)\.com(/|/clip:)(\d+)(.*?)#i',$meta_image,$matches) ) || ( preg_match( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(.*?)#i', $meta_image, $matches ) ) ){
					$meta_image = get_template_directory_uri() .'/styles/_shared/default_movie_thumb_small.png';	
				}
			}
			
			$out .= '<li>';
			
			if($thumbnail == 'true'){
				$out .= '<a class="alignleft" href="' .$permalink. '" title="' .$post_title. '">';
				$out .= '<span class="small_frame"><img class="fade_hover" src="' .$meta_image. '" width="60" height="60" alt="' .$post_title. '"/></span></a>';
			}
			
			$out .= '<a class="thumbnail_title" href="' .$permalink. '" rel="bookmark">' .$post_title. '</a><br/>';
			$out .= '<a class="date" href="' .get_month_link($get_year, $get_month). '">' .$post_date. '</a>';
			$out .= '<div class="clearboth"></div>';
		
			$out .= '</li>';
		}

	$out .= '</ul>';
	$out .= '</div>';
	
	}
	
    return $out;
}
add_shortcode('recent_posts', 'webtreats_recent_post_widget_sc');

/**
 * Popular Blog Posts Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display popular blog posts based on comment count
 */
function webtreats_popular_post_widget_sc($atts) {
	global $wpdb;
	
	extract(shortcode_atts(array(
        	'count'      => '3',
		'thumbnail'      => 'true',
    ), $atts));
	
	$pop_posts = $count;
	$now = gmdate("Y-m-d H:i:s",time());
	$lastmonth = gmdate("Y-m-d H:i:s",gmmktime(date("H"), date("i"), date("s"), date("m")-12,date("d"),date("Y")));
	$popularposts = "SELECT ID, post_title, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'stammy' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' AND post_date < '$now' AND post_date > '$lastmonth' AND comment_status = 'open' GROUP BY $wpdb->comments.comment_post_ID ORDER BY stammy DESC LIMIT ".$pop_posts;
	$posts = $wpdb->get_results($popularposts);
	$popular = '';
	
	if($posts){
		$out .= '<div id="popular-widget" class="scg_widget blog webtreats_popular_widget">';
		$out .= '<ul class="thumbnail_list">';
		
		foreach($posts as $post){
			
			$post_title = stripslashes($post->post_title);
			$post_date = $post->post_date;
			$post_date = mysql2date('m-j-Y', $post_date, false);
			$get_year = get_the_time('Y', $post->ID); $get_month = get_the_time('m', $post->ID);
			$permalink = get_permalink($post->ID);
			$meta_image = get_post_meta($post->ID, "post_image", true);
			
			if(!$meta_image){
				$meta_image = get_template_directory_uri() .'/styles/_shared/default_post_thumb_small.png';
			}else{
				
				if(preg_match_all('!.+\.(?:jpe?g|png|gif)!Ui',$meta_image,$matches)){
					$meta_image = webtreats_image_resize($img_height=60, $img_width=60, $meta_image);
				}
				
				if( ( preg_match_all('#http://(www.vimeo|vimeo)\.com(/|/clip:)(\d+)(.*?)#i',$meta_image,$matches) ) || ( preg_match( '#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\.com/(.*?)#i', $meta_image, $matches ) ) ){
					$meta_image = get_template_directory_uri() .'/styles/_shared/default_movie_thumb_small.png';	
				}
			}
						
			$out .= '<li>';
			
			if($thumbnail == 'true'){
				$out .= '<a class="alignleft" href="' .$permalink. '" title="' .$post_title. '">';
				$out .= '<span class="small_frame"><img class="fade_hover" src="' .$meta_image. '" width="60" height="60" alt="' .$post_title. '"/></span></a>';
			}
			
			$out .= '<a class="thumbnail_title" href="' .$permalink. '" rel="bookmark">' .$post_title. '</a><br/>';
			$out .= '<a class="date" href="' .get_month_link($get_year, $get_month). '">' .$post_date. '</a>';
			$out .= '<div class="clearboth"></div>';
		
			$out .= '</li>';
		} 
		
		$out .= '</ul>';
		$out .= '</div>';
		
	}
	
	return $out;
}
add_shortcode('popular_posts', 'webtreats_popular_post_widget_sc');

/**
 * Recent Comment Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display recent comments
 */
function webtreats_recent_comments_sc($atts) {
	extract(shortcode_atts(array(
        	'number'      => '5',
    ), $atts));

	$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
	$out .= $before_widget;
		$out .= '<div class="widget_recent_comments">';
	$out .= '<ul id="recentcomments">';
	if ( $comments ) {
		foreach ( (array) $comments as $comment) {
			$out .=  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link($comment->comment_ID), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
		}
	}
	$out .= '</div>';
	
	return $out;
	
}
add_shortcode('recent_comments', 'webtreats_recent_comments_sc');

/**
 * Post Tag Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display post tags
 */
function webtreats_post_tag_sc($atts) {
	extract(shortcode_atts(array(
        	'number'      => '100',
    ), $atts));

		$out .= '<div id="tagcloud">';
		
		// do something intelligent to pull attributes to set up the parameters properly, with defaults. (not working yet. deal with it.)
		$listparams = "number=$number&echo=0";
		$out .= '[raw]' .wp_tag_cloud($listparams). '[/raw]';
		$out .='</div>';

		return $out;
	
}
add_shortcode('post_tags', 'webtreats_post_tag_sc');

/**
 * Contact Info Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @return string HTML content to display contact info
 */
function webtreats_contact_info_widget_sc($atts) {
	extract(shortcode_atts(array(
        	'name' => '',
		'address' => '',
		'city' => '',
		'state' => '',
		'zip' => '',
		'phone' => '',
		'email' => '',
		
    ), $atts));
	
	$out .= '[raw]';
	$out .= '<span class="contact_widget_name">' .$name. '</span><br />';
	$out .= '<span class="contact_widget_address">' .$address. '</span><br />';
	$out .= '<span class="contact_widget_city">' .$city. ',&nbsp;' .$state. '</span>&nbsp;';
	$out .= '<span class="contact_widget_zip">' .$zip. '</span><br />';
	$out .= '<span class="contact_widget_phone">' .$phone. '</span><br />';
	$out .= '<span class="contact_widget_email"><a href="#" rel="' .webtreats_nospam($email). '" class="email_widget">' .webtreats_nospam($email). '</a></span><br />';
	$out .= '[/raw]';
	
	return $out;	
}
add_shortcode('contact_info', 'webtreats_contact_info_widget_sc');

/**
 * jQuery Galleria Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display jquery galleria
 */
function webtreats_galleria_sc( $atts, $content = null ) {
	global $post;

	extract(shortcode_atts(array(
		'id' => '1',
        	'transition' => 'fade',
		'height' => '300',
		'width' => '600',
		'autoplay' => 'false',

    ), $atts));

	webtreats_galleria_sc_scripts($transition,$height,$autoplay,$id);
	
	$load_height = $height;
	$galleria_height = $height; $galleria_height +=92;
	$load_width = $width; $load_width -= 18;
	
	if(preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui',$content,$matches)){

		$out .=  '<div id="galleria_' .$id. '" style="width:' .$width. 'px;height:' .$galleria_height. 'px;overflow:hidden;">';

		foreach ($matches[0] as $img) {
			
			$gallery_img = webtreats_image_resize($load_height,$load_width,$img);
			
			$out .= '<a href="' .$gallery_img. '"><img alt="" class="noscript" src="' .webtreats_image_resize($img_height=40, $img_width=60, $img). '" /></a>';
		}
		$out .=  '</div>';

	}

	return $out;
}
add_shortcode('galleria', 'webtreats_galleria_sc');

function webtreats_galleria_sc_scripts($transition,$height,$autoplay,$id) {
	if(!is_feed()){
		$height +=92;
		echo '<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function(){
			jQuery("#galleria_' .$id. '").galleria({
				height: ' .$height. ',
				autoplay: ' .$autoplay. ',
			        transition: "' .$transition. '",
				image_crop: true
			});
		});
		/* ]]> */
		</script>';
	}
}

/**
 * Fancy Image Crop Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display dynamically cropped images
 */
function webtreats_fancy_images_sc( $atts, $content = null ) {
	global $post, $wpdb;
	$post_title = get_the_title($post->ID);
	
	extract(shortcode_atts(array(
		'link' => '',
		'target' => '',
		'title' => '',
		'alt' => '',
		'height' => '200',
		'width' => '188',
	), $atts));
	
	$load_height = $height; $load_height += 18;
	$load_width = $width; $load_width += 18;
	$custom_link = $link;
	
	$inline_style = ' style="background:url(' .get_template_directory_uri(). '/styles/_shared/slider_loader.gif) no-repeat scroll 50% 50% transparent;display:inline-block; height:' .$load_height. 'px; overflow:hidden; padding:0 0 4px 0; position:relative; width:' .$load_width. 'px;"';
	
	$target = ($target == 'blank' || $target == 'parent' || $target == 'self' || $target == 'top') ? $target : '';

	$target = ($target == 'blank') ? ' target="_blank"' : $target;
	$target = ($target == 'parent') ? ' target="_parent"' : $target;
	$target = ($target == 'self') ? ' target="_self"' : $target;
	$target = ($target == 'top') ? ' target="_top"' : $target;
	
	
	if(preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui',$content,$matches)){
		
		$out .=  '<ul class="webtreats_mini_gallery_widget">';
		
		foreach ($matches[0] as $img) {
			$image_url = webtreats_image_resize($height,$width,$img);
			
			$link = ($custom_link) ? ' href="' .$custom_link. '"' .$target : ' rel="lightbox[small_gallery]" href="' .$img. '"';
			
			$out .=  '<li class="alignleft webtreats_mini_gallery_item img_loader bg_hover">';
			$out .= '<a title="' .$title. '" class="load_img"' .$inline_style.$link. '>';
			$out .= '<span class="rm_img noscript"><img class="framed portfolio_hover" height="' .$height. '" width="' .$width. '" alt="' .$alt. '" title="' .$title. '" src="' .$image_url. '" /></span>';
			$out .=  '</a>';
			$out .=  '</li>';
		}
		
	$out .=  '</ul>';
	
	$out .= '<div class="clearboth"></div>';	
		
	}
	
	return $out;
	
}
add_shortcode('fancy_images', 'webtreats_fancy_images_sc');


/**
 * Image frame Shortcode
 *
 */
function webtreats_frame_left( $atts, $content = null ) {
	extract(shortcode_atts(array(
        	'alt' => '',
		'title' => '',
    ), $atts));

	if(preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui',$content,$matches)){
		foreach ($matches[0] as $img) {
			 $left_img = webtreats_image_format($img, $class='alignleft', $alt, $title);
				return $left_img;
			}
	}
}
add_shortcode('frame_left', 'webtreats_frame_left');


function webtreats_frame_right( $atts, $content = null ) {
	extract(shortcode_atts(array(
        	'alt' => '',
		'title' => '',
    ), $atts));

	if(preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui',$content,$matches)){
		foreach ($matches[0] as $img) {
			 $right_img = webtreats_image_format($img, $class='alignright', $alt, $title);
				return $right_img;
			}
	}
}
add_shortcode('frame_right', 'webtreats_frame_right');


function webtreats_frame_center( $atts, $content = null ) {
	extract(shortcode_atts(array(
        	'alt' => '',
		'title' => '',
    ), $atts));
	
	if(preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui',$content,$matches)){
		foreach ($matches[0] as $img) {
			 $center_img = webtreats_image_format($img, $class='aligncenter', $alt, $title);
				return $center_img;
			}
	}
}
add_shortcode('frame_center', 'webtreats_frame_center');


/**
 * jQuery Tools Tabs Minimalist Styled Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display jQuery tools minimalist styled tabs
 */
function webtreats_minimal_tabs_set_sc( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));

	
	$out .= '[raw]<div class="minimal_arrow_tab_set">[/raw]';
	
	$out .= '<ul class="tabs">';
	foreach ($atts as $tab) {
		$out .= '<li><a href="#">' .$tab. '</a></li>';
	}
	$out .= '</ul>';

	$out .= do_shortcode($content) .'[raw]</div>[/raw]';
	
	return $out;
	
}
add_shortcode('minimal_tabs', 'webtreats_minimal_tabs_set_sc');

/**
 * jQuery Tools Tabs Framed Styled Shortcode
 *
 * @param array $atts User defined attributes in shortcode tag
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display jQuery tools framed styled tabs
 */
function webtreats_framed_tabs_set_sc( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));

	
	$out .= '[raw]<div class="framed_tab_set">[/raw]';
	
	$out .= '<ul class="tabs">';
	foreach ($atts as $tab) {
		$out .= '<li><a href="#">' .$tab. '</a></li>';
	}
	$out .= '</ul>';

	$out .= do_shortcode($content) .'[raw]</div>[/raw]';
	
	return $out;
	
}
add_shortcode('framed_tabs', 'webtreats_framed_tabs_set_sc');

function custom_tabs_sc( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));

	
	$out .= '[raw]<div class="tab_content">[/raw]' . do_shortcode($content) .'</div>';
	
	return $out;
}
add_shortcode('tab', 'custom_tabs_sc');


/**
 * Tooltip Shortcode 
 */
function webtreats_tooltip_sc( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'trigger' => '',
		'width' => '132',
    ), $atts));

	if( (stristr( $trigger, '<img' )) || (stristr( $trigger, 'class="button_link"' )) || (stristr( $trigger, 'class="download_link"' )) || (stristr( $trigger, 'class="fancy_link"' )) ){
		
		$class = ( stristr( $trigger, 'class="button_link"' )) ? 'tooltip_btn_sc' : 'tooltip_sc';
		$width = 'width:' .$width. 'px;';
		
		$out .= '[raw]<span class="' .$class. '" style="display:inline-block;">' . $trigger .'</span>[/raw]';
		$out .= '[raw]<div class="tool_tip">';
		$out .= '<div style="position:relative;' .$width. '">';
		$out .= '<div class="tooltip_body">' . do_shortcode($content) . '</div>';
		$out .= '<div class="tooltip_tip"></div>';
		$out .= '</div>';
		$out .= '</div>[/raw]';
	}else{
		$out .= '<a class="tooltip_text" title="' .$content. '" href="#" onclick="return false;">' .$trigger. '</a>';
	}

	return $out;
}
add_shortcode('tooltip', 'webtreats_tooltip_sc');


/**
 * Fancy Table Shortcode 
 */
function webtreats_fancy_table_sc( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));

	$out = str_replace('<table>', '<table class="fancy_table">', $content);
	
	return $out;
}
add_shortcode('fancy_table', 'webtreats_fancy_table_sc');

/**
 * Contact Form Shortcode 
 *
 * @param array $atts User defined attributes in shortcode tag
 * @param string $content Optional. Shortcode content.
 * @return string HTML content to display contact form
 */
function custom_contact_form_sc( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'email'      => '',
    ), $atts));
    
    $out = webtreats_contact_form($email);
    
    return $out;
}
add_shortcode('contactform', 'custom_contact_form_sc');


/**
 * Buttons/Links Shortcodes
 *
 */
function webtreats_button( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'link'      => '#',
	'target'      => '',
	'variation'      => '',
	'size'      => '',
	'align'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_gradient' : '';
	
	$align = ($align) ? ' align'.$align : '';
	
	$size = ($size == 'large') ? ' large_button' : '';
	
	$target = ($target == 'blank' || $target == 'parent' || $target == 'self' || $target == 'top') ? $target : '';
	
	$target = ($target == 'blank') ? ' target="_blank"' : $target;
	$target = ($target == 'parent') ? ' target="_parent"' : $target;
	$target = ($target == 'self') ? ' target="_self"' : $target;
	$target = ($target == 'top') ? ' target="_top"' : $target;

	$out = '<a' .$target. ' class="button_link' .$style.$size.$align. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
    
    return $out;
}
add_shortcode('button', 'webtreats_button');

function webtreats_fancy_link( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'link'      => '#',
	'target'      => '',
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_fancy' : '';

	$target = ($target == 'blank' || $target == 'parent' || $target == 'self' || $target == 'top') ? $target : '';
	
	$target = ($target == 'blank') ? ' target="_blank"' : $target;
	$target = ($target == 'parent') ? ' target="_parent"' : $target;
	$target = ($target == 'self') ? ' target="_self"' : $target;
	$target = ($target == 'top') ? ' target="_top"' : $target;

	$out = '<a' .$target. ' class="fancy_link' .$style. '" href="' .$link. '">' .do_shortcode($content). '</a>';
    
    return $out;
}
add_shortcode('fancy_link', 'webtreats_fancy_link');

function webtreats_download_link( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'link'      => '#',
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_icons' : '';

	$out = '<a class="download_link' .$style. '" href="' .$link. '">' .do_shortcode($content). '</a>';
    
    return $out;
}
add_shortcode('download_link', 'webtreats_download_link');

function webtreats_email_link( $atts, $content = null ) {
    extract(shortcode_atts(array(
        'email'      => '#',
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_icons' : '';

	$out = '<a class="email_link email' .$style. '" href="#" rel="' .webtreats_nospam($email). '">' .do_shortcode($content). '</a>';
	
    
    return $out;
}
add_shortcode('email_link', 'webtreats_email_link');


/** 
* Header Shortcodes
* 
*/
function webtreats_fancy_header( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' class="' .$variation. '_background"' : '';
	
   return '<h6 class="fancy_header"><span' .$style. '>' .do_shortcode($content). '</span></h6>';
}
add_shortcode('fancy_header', 'webtreats_fancy_header');


/** 
* Teaser Shortcodes
* 
*/
function webtreats_teaser( $atts, $content = null ) {
	extract(shortcode_atts(array(
 		'variation'      => '',
   ), $atts));
	$style = ($variation) ? ' '.$variation. '_color' : '';
	
   return '[raw]<p class="teaser">' .do_shortcode($content). '</p>[/raw]';
}
add_shortcode('teaser', 'webtreats_teaser');

function webtreats_teaser_large( $atts, $content = null ) {
	extract(shortcode_atts(array(
 		'variation'      => '',
   ), $atts));
	$style = ($variation) ? ' '.$variation. '_color' : '';
	
   return '[raw]<p class="teaser_large">' .do_shortcode($content). '</p>[/raw]';
}
add_shortcode('teaser_large', 'webtreats_teaser_large');



/** 
* Dropcaps Shortcodes
* 
*/
function webtreats_drop_cap_1( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_sprite' : '';

   return '<span class="dropcap1' .$style. '">' . do_shortcode($content) . '</span>';
}
add_shortcode('dropcap1', 'webtreats_drop_cap_1');


function webtreats_drop_cap_2( $atts, $content = null ) {
   return '<span class="dropcap2">' . do_shortcode($content) . '</span>';
}
add_shortcode('dropcap2', 'webtreats_drop_cap_2');


function webtreats_drop_cap_3( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_sprite' : '';

   return '<span class="dropcap3' .$style. '">' . do_shortcode($content) . '</span>';
}
add_shortcode('dropcap3', 'webtreats_drop_cap_3');


function webtreats_drop_cap_4( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_color' : '';

   return '<span class="dropcap4' .$style. '">' . do_shortcode($content) . '</span>';
}
add_shortcode('dropcap4', 'webtreats_drop_cap_4');


/** 
* Pullquotes Shortcodes
* 
*/
function webtreats_pullquote_right( $atts, $content = null ) {
   return '<span class="pullquote_right">' . do_shortcode($content) . '</span>';
}
add_shortcode('pullquote_right', 'webtreats_pullquote_right');


function webtreats_pullquote_left( $atts, $content = null ) {
   return '<span class="pullquote_left">' . do_shortcode($content) . '</span>';
}
add_shortcode('pullquote_left', 'webtreats_pullquote_left');


/** 
* Box Styles Shortcodes
* 
*/
function webtreats_download_box( $atts, $content = null ) {
   return '<div class="download_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('download_box', 'webtreats_download_box');


function webtreats_warning_box( $atts, $content = null ) {
   return '<div class="warning_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('warning_box', 'webtreats_warning_box');


function webtreats_info_box( $atts, $content = null ) {
   return '<div class="info_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('info_box', 'webtreats_info_box');


function webtreats_note_box( $atts, $content = null ) {
   return '<div class="note_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('note_box', 'webtreats_note_box');


function webtreats_simple_box( $atts, $content = null ) {
   return '<div class="simple_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('simple_box', 'webtreats_simple_box');


function webtreats_fancy_box( $atts, $content = null ) {
   return '<div class="fancy_box">' . do_shortcode($content) . '</div>';
}
add_shortcode('fancy_box', 'webtreats_fancy_box');


function webtreats_fancy_titled_box( $atts, $content = null ) {
	extract(shortcode_atts(array(
        'title'      => '',
    ), $atts));
	
	$out .= '<div class="fancy_titled_box">';
	$out .= '<h3 class="fancy_titled_box_header">' .$title. '</h3>';
	$out .= '<div class="fancy_titled_box_content">';
	$out .= do_shortcode($content);
	$out .= '</div>';
	$out .= '</div>';
	
   return $out;
}
add_shortcode('fancy_titled_box', 'webtreats_fancy_titled_box');

function webtreats_color_box( $atts, $content = null ) {
	extract(shortcode_atts(array(
        'title'      => '',
        'align'      => '',
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_gradient' : '';
	
	$align = ($align) ? ' style="text-align:'.$align.'"' : '';
	
	$out .= '<div class="color_scheme_box">';
	$out .= '<h6 '.$align.' class="color_scheme_box_header' .$style. '"><span>' .$title. '</span></h6>';
	$out .= '<div class="color_scheme_box_content">';
	$out .= do_shortcode($content);
	$out .= '</div>';
	$out .= '</div>';
	
   return $out;
}
add_shortcode('color_box', 'webtreats_color_box');


/** 
* List Styles Shortcodes
* 
*/
function webtreats_check_list( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' class="'.$variation. '_icons"' : '';

	$content = str_replace('<ul>', '<ul class="check_list">', do_shortcode($content));
	$content = str_replace('<li>', '<li' .$style. '>', do_shortcode($content));
	
	return $content;
	
}
add_shortcode('check_list', 'webtreats_check_list');


function webtreats_arrow_list( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));
	
	$style = ($variation) ? ' class="'.$variation. '_icons"' : '';
	
	$content = str_replace('<ul>', '<ul class="arrow_list">', do_shortcode($content));
	$content = str_replace('<li>', '<li' .$style. '>', do_shortcode($content));
	
	return $content;
	
}
add_shortcode('arrow_list', 'webtreats_arrow_list');


function webtreats_star_list( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' class="'.$variation. '_icons"' : '';

	$content = str_replace('<ul>', '<ul class="star_list">', do_shortcode($content));
	$content = str_replace('<li>', '<li' .$style. '>', do_shortcode($content));
	
	return $content;
	
}
add_shortcode('star_list', 'webtreats_star_list');


function webtreats_bullet_list( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'variation'      => '',
    ), $atts));
	
	$style = ($variation) ? ' '.$variation. '_color' : '';
	
	$content = str_replace('<ul>', '<ul class="bullet_list' .$style. '">', do_shortcode($content));
	return $content;
	
}
add_shortcode('bullet_list', 'webtreats_bullet_list');


/** 
* jQuery Content Toggle Shortcode
* 
*/
function webtreats_toggle_content( $atts, $content = null ) {
	extract(shortcode_atts(array(
        'title'      => '',
	'variation'      => '',
    ), $atts));

	$style = ($variation) ? ' '.$variation. '_toggle' : '';
	
	$out .= '<h4 class="toggle' .$style. '"><a href="#">' .$title. '</a></h4>';
	$out .= '<div class="toggle_content" style="display: none;">';
	$out .= '<div class="block">';
	$out .= do_shortcode($content);
	$out .= '</div>';
	$out .= '</div>';
	
   return $out;
}
add_shortcode('toggle', 'webtreats_toggle_content');


function webtreats_toggle_framed_content( $atts, $content = null ) {
	extract(shortcode_atts(array(
        'title'      => '',
	'variation'      => '',
    ), $atts));
	
	$style = ($variation) ? ' '.$variation. '_toggle' : '';
	
	$out .= '<div class="toggle_frame">';
	$out .= '<h4 class="toggle' .$style. '"><a href="#">' .$title. '</a></h4>';
	$out .= '<div class="toggle_content" style="display: none;">';
	$out .= '<div class="block">';
	$out .= do_shortcode($content);
	$out .= '</div>';
	$out .= '</div>';
	$out .= '</div>';
	
   return $out;
}
add_shortcode('toggle_framed', 'webtreats_toggle_framed_content');


/** 
* Highlight Shortcodes
* 
*/
function webtreats_highlight1( $atts, $content = null ) {
   return '<span class="highlight1">' . do_shortcode($content) . '</span>';
}
add_shortcode('highlight1', 'webtreats_highlight1');


function webtreats_highlight2( $atts, $content = null ) {
   return '<span class="highlight2">' . do_shortcode($content) . '</span>';
}
add_shortcode('highlight2', 'webtreats_highlight2');


/**
 * Divider Styles Shortcodes
 *
 */
function webtreats_divider( $atts ) {
   return '<div class="divider"></div>';
}
add_shortcode('divider', 'webtreats_divider');


function webtreats_divider_top( $atts ) {
   return '<div class="divider top"><a href="#">Top</a></div>';
}
add_shortcode('divider_top', 'webtreats_divider_top');


function webtreats_clearboth( $atts ) {
   return '<div class="clearboth"></div>';
}
add_shortcode('clearboth', 'webtreats_clearboth');


function webtreats_divider_padding( $atts ) {
   return '<div class="divider_padding"></div>';
}
add_shortcode('divider_padding', 'webtreats_divider_padding');


/** 
* DIV and SPAN Shortcodes
* 
*/
function webtreats_div( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'style'      => '',
		'class'      => '',
    ), $atts));
	
   return '<div class="'.$class.'" style="'.$style.'">' .do_shortcode($content). '</div>';
}
add_shortcode('div', 'webtreats_div');

function webtreats_span( $atts, $content = null ) {
	extract(shortcode_atts(array(
	'style'      => '',
	'class'      => '',
    ), $atts));
	
   return '<span class="'.$class.'" style="'.$style.'">' .do_shortcode($content). '</span>';
}
add_shortcode('span', 'webtreats_span');


/**
 * Columns Shortcodes
 *
 */
function webtreats_one_third( $atts, $content = null ) {
   return '<div class="one_third">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_third', 'webtreats_one_third');


function webtreats_one_third_last( $atts, $content = null ) {
   return '<div class="one_third last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_third_last', 'webtreats_one_third_last');


function webtreats_two_third( $atts, $content = null ) {
   return '<div class="two_third">' . do_shortcode($content) . '</div>';
}
add_shortcode('two_third', 'webtreats_two_third');


function webtreats_two_third_last( $atts, $content = null ) {
   return '<div class="two_third last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('two_third_last', 'webtreats_two_third_last');


function webtreats_one_half( $atts, $content = null ) {
   return '<div class="one_half">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_half', 'webtreats_one_half');


function webtreats_one_half_last( $atts, $content = null ) {
   return '<div class="one_half last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_half_last', 'webtreats_one_half_last');


function webtreats_one_fourth( $atts, $content = null ) {
   return '<div class="one_fourth">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_fourth', 'webtreats_one_fourth');


function webtreats_one_fourth_last( $atts, $content = null ) {
   return '<div class="one_fourth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_fourth_last', 'webtreats_one_fourth_last');


function webtreats_three_fourth( $atts, $content = null ) {
   return '<div class="three_fourth">' . do_shortcode($content) . '</div>';
}
add_shortcode('three_fourth', 'webtreats_three_fourth');


function webtreats_three_fourth_last( $atts, $content = null ) {
   return '<div class="three_fourth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('three_fourth_last', 'webtreats_three_fourth_last');



/**
 * Additional Column Shortcodes
 *
 */
function webtreats_one_fifth( $atts, $content = null ) {
   return '<div class="one_fifth">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_fifth', 'webtreats_one_fifth');


function webtreats_one_fifth_last( $atts, $content = null ) {
   return '<div class="one_fifth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_fifth_last', 'webtreats_one_fifth_last');


function webtreats_two_fifth( $atts, $content = null ) {
   return '<div class="two_fifth">' . do_shortcode($content) . '</div>';
}
add_shortcode('two_fifth', 'webtreats_two_fifth');


function webtreats_two_fifth_last( $atts, $content = null ) {
   return '<div class="two_fifth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('two_fifth_last', 'webtreats_two_fifth_last');


function webtreats_three_fifth( $atts, $content = null ) {
   return '<div class="three_fifth">' . do_shortcode($content) . '</div>';
}
add_shortcode('three_fifth', 'webtreats_three_fifth');


function webtreats_three_fifth_last( $atts, $content = null ) {
   return '<div class="three_fifth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('three_fifth_last', 'webtreats_three_fifth_last');


function webtreats_four_fifth( $atts, $content = null ) {
   return '<div class="four_fifth">' . do_shortcode($content) . '</div>';
}
add_shortcode('four_fifth', 'webtreats_four_fifth');


function webtreats_four_fifth_last( $atts, $content = null ) {
   return '<div class="four_fifth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('four_fifth_last', 'webtreats_four_fifth_last');


function webtreats_one_sixth( $atts, $content = null ) {
   return '<div class="one_sixth">' . do_shortcode($content) . '</div>';
}
add_shortcode('one_sixth', 'webtreats_one_sixth');


function webtreats_one_sixth_last( $atts, $content = null ) {
   return '<div class="one_sixth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('one_sixth_last', 'webtreats_one_sixth_last');


function webtreats_five_sixth( $atts, $content = null ) {
   return '<div class="five_sixth">' . do_shortcode($content) . '</div>';
}
add_shortcode('five_sixth', 'webtreats_five_sixth');


function webtreats_five_sixth_last( $atts, $content = null ) {
   return '<div class="five_sixth last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
}
add_shortcode('five_sixth_last', 'webtreats_five_sixth_last');


?>